import { observable, action } from 'mobx';
import { Bubble, Tools, Toast } from 'weaver-mobile';
import { ListViewPage } from 'weaver-mobile-page';
import * as Api from '../../api/apply';

const getLabel = Tools.getLabel;

const initalState = {
  quitLoading: true,
}
export default class QuitedCoworkStore {
  @observable quitedList = new ListViewPage.Store({ route: '/apply', id: 'quited' }); //已退出协作
  @observable quitLoading = initalState.quitLoading;

  @action setStoreState = (params) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    })
  }
  
  @action getCoworkApplyPageList = () => {
    let params = {topKey: 'applyquited'}
    Api.getCoworkApplyPageList(params).then(res => {
      const dataKey = res.sessionkey;
      this.quitedList.getData({ dataKey }, () => this.quitLoading = false, true);// ture是否刷新用
    })
  }

  @action("申请加入操作")
  coworkApplayInfo = (params) => {
    let coworkIds = params.coworkIds;
    if(coworkIds === ""){
      Toast.info(getLabel(390682, '请选择要加入的主题')+'!', 1);
      return;
    }
    const finalParams = {
      ...params,
    };
    Api.coworkApplayInfo(finalParams).then((result) => {
      const status = result.status;
      if (status === "1") {
        Bubble.success(getLabel(390683, '申请成功，请等待审批')+'!', 1);
        this.getCoworkApplyPageList();
      }
    })
  }
}